package cn.rxmind.dlog.common.rule;

import cn.rxmind.dlog.common.annotation.CollectLog;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.reflect.MethodSignature;

import java.util.function.Predicate;

/**
 *
 * @description 通过CollectLog注解判定日志数据是否应该被采集
 *
 * @author renxin
 * @email renxinzhiliangzhi@163.com
 * @date 2020/7/13 3:01 下午
 */
public class AnnotationNeedCopy implements Predicate<JoinPoint> {

    @Override
    public boolean test(JoinPoint joinPoint) {
        Signature signature = joinPoint.getSignature();
        if(signature instanceof MethodSignature) {
            MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
            return methodSignature.getMethod().getAnnotation(CollectLog.class) != null || methodSignature.getDeclaringType().getAnnotation(CollectLog.class) != null;

        }
        return false;
    }
}
